<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 原本的实现方法
        // function Teacher() {}
        // function Student() {}
        // function Buffer() {}
        // Buffer.prototype = Teacher.prototype
        // var buffer = new Buffer()
        // Student.prototype = buffer

        // var s = new Student()
        // var t = new Teacher()

        // 进行标准方法的封装
        // function inherit(Target, Origin) {
        //     function Buffer() {}
        //     Buffer.prototype = Origin.prototype
        //     Target.prototype = new Buffer()

        // 下面的方法为还原构造器，设置继承源
        //     Target.prototype.constructor = Target
        //     Target.prototype.super_class = Origin
        // }

        // 调用
        // function Teacher() {}
        // function Student() {}
        // inherit(Student, Teacher)

        // var s = new Student()
        // var t = new Teacher()
        

        // 企业级封装 （使用闭包的方式通过自调用执行）
        // 通过自调用函数创建一个私有作用域，模块化开发，防止了全局污染变量
        var inherit = (function() {
            var Buffer= function() {}
            return function(Target, Origin) {
                Buffer.prototype = Origin.prototype
                Target.prototype = new Buffer()
                Target.prototype.constructor = Target
                Target.prototype.super_class = Origin 
            }
        })();

        // 调用
        Teacher.prototype.name = '单宇宸'
        function Teacher() {}
        function Student() {}
        inherit(Student, Teacher)

        Student.prototype.age = 18
        Student.prototype.name = 'Trist'
        var s = new Student()
        var t = new Teacher()

        console.log(s)
        console.log(t)
    </script>
</body>
</html>